package com.syx.extensiondemo.Listener;

import com.rabbitmq.client.Channel;
import com.syx.extensiondemo.Constant.Constants;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

@Component
public class ackListener {
    @RabbitListener(queues = Constants.ACK_QUEUE)
    public void handMessage(Message message,Channel channel) throws Exception {

        long deliveryTag = message.getMessageProperties().getDeliveryTag();
        /*int a=3/0;*/
        try {
            System.out.println(message.getMessageProperties().getDeliveryTag()+"///////"+new String(message.getBody(), StandardCharsets.UTF_8));
            //int c=3/0;
            channel.basicAck(deliveryTag,false);

        } catch (Exception e) {
            //出现异常后否定确认
            channel.basicNack(deliveryTag,false,true);
        }

    }



}
